﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ADShop.Models;
using System.Web.Routing;
namespace ADShop.Areas.Admin.Controllers
{
    public class ShipMethodController : Controller
    {
        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            base.OnActionExecuting(filterContext);
            if (Session["Admin"] == null)
            {
                filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new
                {
                    controller = "Oops",
                    action = "Index"
                }));
            }
        }
        //private ADShopEntities db = new ADShopEntities();
        private EShopEntities1 db = new EShopEntities1();

        //
        // GET: /Admin/ShipMethod/

        public ActionResult Index()
        {
            return View(db.ShipMethod.ToList());
        }

        //
        // GET: /Admin/ShipMethod/Details/5

        public ActionResult Details(int id = 0)
        {
            ShipMethod shipmethod = db.ShipMethod.Find(id);
            if (shipmethod == null)
            {
                return HttpNotFound();
            }
            return View(shipmethod);
        }

        //
        // GET: /Admin/ShipMethod/Create

        public ActionResult Create()
        {
            return View();
        }

        //
        // POST: /Admin/ShipMethod/Create

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Create(ShipMethod shipmethod)
        {
            if (ModelState.IsValid)
            {
                db.ShipMethod.Add(shipmethod);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(shipmethod);
        }

        //
        // GET: /Admin/ShipMethod/Edit/5

        public ActionResult Edit(int id = 0)
        {
            ShipMethod shipmethod = db.ShipMethod.Find(id);
            if (shipmethod == null)
            {
                return HttpNotFound();
            }
            return View(shipmethod);
        }

        //
        // POST: /Admin/ShipMethod/Edit/5

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Edit(ShipMethod shipmethod)
        {
            if (ModelState.IsValid)
            {
                db.Entry(shipmethod).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(shipmethod);
        }

        //
        // GET: /Admin/ShipMethod/Delete/5

        public ActionResult Delete(int id = 0)
        {
            ShipMethod shipmethod = db.ShipMethod.Find(id);
            if (shipmethod == null)
            {
                return HttpNotFound();
            }
            return View(shipmethod);
        }

        //
        // POST: /Admin/ShipMethod/Delete/5

        [HttpPost, ActionName("Delete")]
        [ValidateAntiForgeryToken]
        public ActionResult DeleteConfirmed(int id)
        {
            ShipMethod shipmethod = db.ShipMethod.Find(id);
            db.ShipMethod.Remove(shipmethod);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}